/**
  ******************************************************************************
* @file				iic_at24.c
* @Software			MDK V5
* @Target 			MM32F533
* @author			ou_teki
* @date				2024-0420
  ******************************************************************************
  */

#include "iic_at24.h"

//-TKW24-0716-IIC Init
//-I2C2_SDA->PC9  I2C2_SCL-PC8 
uint8_t AT24_IIC_Init(void)
{
    //-TKW24-0716-Clock Config
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
    //-TKW24-0716-GPIO Config
    GPIO_InitTypeDef gpio_iic_init_s;
    gpio_iic_init_s.GPIO_Mode = GPIO_Mode_AF_OD;
    gpio_iic_init_s.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_8;
    gpio_iic_init_s.GPIO_Speed = GPIO_Speed_High;
    GPIO_Init(GPIOC, &gpio_iic_init_s);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_4);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_4);

    //-TKW24-0716-IIC Config
    I2C_InitTypeDef iic_init_s;
    iic_init_s.I2C_Mode = I2C_MODE_MASTER;
    iic_init_s.I2C_OwnAddress = I2C_OWN_ADDRESS;
    iic_init_s.I2C_ClockSpeed = 100000;
    I2C_Init(I2C2, &iic_init_s);

    I2C_Cmd(I2C2, ENABLE);

    return 0;
}


uint8_t AT24_IIC_TransmitData(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t size)
{
    if(size == 0)       return 1;
    if(data == NULL)    return 2;

    // I2C_TargetAddressConfig(I2C2, dev_addr);


    return 0;
}


uint8_t AT24_IIC_ReceiveData(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t size)
{
    if(size == 0)       return 1;
    if(data == NULL)    return 2;
        
    return 0;
}


/********************************End of File************************************/


